<template>
  <div>
    <Card title="修改密码" style="width:500px">
      <Row>
        <Input v-model="OldPwd" type="password" size="large" placeholder="原密码"/>
      </Row>
      <br>
      <Row>
        <Input v-model="NewPwd" type="password" size="large" placeholder="新密码"/>
      </Row>
      <br>
      <Row>
        <Input v-model="ReNewPwd" type="password" size="large" placeholder="确认新密码"/>
      </Row>
       <br>
       <Row>
        <Button size="large" type="primary" @click="UpdatePwd" >确认修改</Button>
      </Row>
    </Card>
  </div>
</template>

<script>
import { Message } from "view-design";
import { UpdatePwd } from "@/api/data";
import { getUserInfo, setToken, setAccess } from "@/libs/util";
export default {
  name: "updatepwd",
  data() {
    return {
      OldPwd: "",
      NewPwd: "",
      ReNewPwd: ""
    };
  },
  methods: {
    UpdatePwd() {
      let vm = this;
      if (!this.OldPwd) {
        Message.error("原密码不能为空");
        return;
      }
      if (!this.NewPwd) {
        Message.error("新密码不能为空");
        return;
      }
      if (!this.ReNewPwd) {
        Message.error("确认新密码不能为空");
        return;
      }
      if (this.ReNewPwd != this.NewPwd) {
        Message.error("两次输入的密码不一致");
        return;
      }
      var reqData = {
        gid: getUserInfo().Gid,
        oldpwd: this.OldPwd,
        newpwd: this.NewPwd,
        renewpwd: this.ReNewPwd
      };

      UpdatePwd(reqData).then(res => {
        const data = res.data;
        if (data.Type == 1) {
          Message.success("密码修改成功，请重新登录");
          setToken("");
          setAccess("");
          this.$router.push({
            name: "login"
          });
        } else {
          this.$Modal.error({ title: "提示", content: data.Message });
        }
      });
    }
  }
};
</script>

<style>
</style>
